<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/12/17
  Time: 17:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html" ;charset="gb2312">
    <title>CoolMeeting会议管理系统</title>
    <link rel="stylesheet" href="styles/common.css" />
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script>
        var dept;
        $(function(){//编辑
            $('.update').click(function(){
                var Deptname =$(this).parents('tr').children(':eq(1)');
                dept =Deptname.text();
                Deptname.html('<input type="text" name="newname" value="'+dept+'"/>');

                //Deptname.html('<input name="newname" type="text" value="'+dept+'"/>')
                //Deptname.html('<input name="newname" type="text" value="'+dept+'"/>');
                $(this).hide();
                $(this).next().show();
                $(this).next().next().show();
            });
        });

        $(function(){//取消
            $('.confrim').click(function(){
                var Deptname =$(this).parents('tr').children(':eq(1)');
                Deptname.html(dept);
                $(this).prev().prev().show();
                $(this).prev().hide();
                $(this).hide();

            });
        });



       /* function sub(me,path,id){
            var str = $(me).parents('tr').children(':eq(1)').children().val();
            var newname =$(me).parents('tr').children(':eq(1)').html(str);
           window.location.href = path+"/updateDeptServlet?departmentid=" + id +"&newname="+ newname;
        }*/



        function del(departmentid){
            var flag = confirm("确定删除"+departmentid+"号部门吗？");
            if(flag){
                // 跳转到删除部门的servlet，并传递请求参数部门编号deptno

                location.href = "<%=request.getContextPath() %>/deleteDeptServlet?departmentid="+departmentid;
            }
        }
        function submit(departmentid){
            var flag = confirm("确定修改"+departmentid+"号部门的名称?");
            if(flag){
                location.href = "<%=request.getContextPath() %>/updateDeptServlet?departmentid="+departmentid+"&"+"newname="+$('input[name=newname]').val();
            }

        }

    </script>
</head>

<body>

<div class="page-content">
    <div class="content-nav">
        人员管理 > 部门管理
    </div>
    <form action="${pageContext.request.contextPath }/insertDeptServlet">
        <fieldset>
            <legend>添加部门</legend>
            部门名称:
            <input type="text" name="departmentname" maxlength="20" />
            <input type="submit" class="clickbutton" value="添加" />
            ${msg}
        </fieldset>
    </form>
    <table class="listtable">
        <caption>所有部门:</caption>
        <tr class="listheader">
            <th>部门编号</th>
            <th>部门名称</th>
            <th>操作</th>
        </tr>
            <form action="${pageContext.request.contextPath }/updateDeptServlet" name="form1">
            <c:forEach items="${departments }" var="department">
                <tr>
                    <td name="departmentid">${department.departmentid }</td>
                    <td name="departmentname">${department.departmentname }</td>
                    <td>
                        <a class="update" href="#')">编辑</a>
                        <%--<a class="updatedept" href="${pageContext.request.contextPath }/updateDeptServlet?departmentid=${department.departmentid }&departmentname" style="display: none;">提交</a>--%>
                        <a class="updatedept" href="javascript:submit('${department.departmentid}');" style="display: none;">提交</a>
                        <%--<a class="updatedept" href="javascript:submit();" style="display: none;">提交</a>--%>
                        <a class="confrim" href="#" style="display: none;">取消</a>
                       <a href="javascript:del(${department.departmentid })" class="tablelink"> 删除</a>
                    </td>
                </tr>
            </c:forEach>
            </form>
    </table>
</div>

</body>

</html>
